//
//  ViewController.m
//  TestJSOC
//
//  Created by yfmac001 on 2018/4/6.
//  Copyright © 2018年 yfmac001. All rights reserved.
//

#import "ViewController.h"
#import <WebKit/WebKit.h>
#import "WKWebViewJavascriptBridge.h"
@interface ViewController ()
///WKWebView
@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) WKWebViewJavascriptBridge *bridge;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.webView = [[WKWebView alloc]initWithFrame:self.view.bounds];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"demo" withExtension:@"html"]];
    [self.webView loadRequest:request];
    
    [self.view addSubview:self.webView];
    
    //初始化bridge
    self.bridge = [WKWebViewJavascriptBridge bridgeForWebView:self.webView];
    [self.bridge registerHandler:@"setData" handler:^(id data, WVJBResponseCallback responseCallback) {
        //这里的data为JS发送给OC的数据
        NSLog(@"----------%@", data);
        
        
        //OC调用JS
        [_bridge callHandler:@"getData" data:@"OC传来的数据l, 哈哈哈"];
    }];
}





@end
